<template>
    <div class="cata">
        <el-breadcrumb separator="/" class="catas">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item><a href="/">商品管理</a></el-breadcrumb-item>
          <el-breadcrumb-item>商品分类</el-breadcrumb-item>
        </el-breadcrumb>
        <el-button type="primary" plain>添加用户</el-button>
        <tree-grid
        class="mt-15"
     :treeStructure="true"
     :columns="columns"
     :data-source="dataSource"
     @deleteCate="deleteCategory"
     @editCate="editCategory">
        </tree-grid>
        <el-pagination
      class="page"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="10"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNum">
    </el-pagination>
    <!--  -->
    <el-dialog title="添加用户" :visible.sync="editDialogFormVisible">
  <el-form :model="editForm" :rules="myRules" ref="editRef">
    <el-form-item label="分类名称" label-width="90px" prop="username">
      <el-input v-model="editForm.username" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="父类名称" label-width="90px">
      <!-- change-on-select属性用于控制可以选择任意一级数据 -->
    <el-cascader
    change-on-select
    :options="options"
    :props="defaultProps"
    v-model="selectedOptions"
    @change="handleChange">
  </el-cascader>
  </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="editDialogFormVisible = false">取 消</el-button>
    <el-button type="primary" @click="editTxt">确 定</el-button>
  </div>
</el-dialog>
    </div>
</template>
<script>
import treeGrid from '@/components/TreeGrid/TreeGrid'
import { categoriesList } from '@/api'
export default {
  components: {
    treeGrid
  },
  data () {
    return {
      editDialogFormVisible: false,
      dataSource: [],
      editForm: [],
      myrules: {
        cat_name: [
          { required: true, message: '请输入用户名', trigger: 'blur' }
        ]
      },
      columns: [],
      handleChange (value) {
        console.log(value)
      }
    }
  },
  created () {
    this.initTable()
  },
  methods: {
    initTable () {
      categoriesList(3, this.pagenum, this.pagesize)
        .then(res => {
          this.dataSource = res.data.data.result
          this.totalNum = res.data.data.total
        })
    },
    deleteCategory (cid) {
      console.log(cid)
    },
    editCategory (cid) {
      console.log(cid)
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.pagesize = val
      this.initTable()
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.pagenum = val
      this.initTable()
    },
    editTxt () {
      this.editDialogFormVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
.catas {
  background-color: #F5F5F5;
  height: 45px;
  font-size: 15px;
  padding-left: 10px;
  line-height: 45px;
  margin-bottom: 15px;
}
.el-button{
    margin-bottom: 15px;
}
</style>
